package day09;

import java.io.*;

/**
 * FileInputStream: 字节输入流
 */
public class StreamInput {

    public static void main(String[] args) {
        readFile(filePath());
        readImage(imagePath());
    }

    public static String filePath() {
        return "src/test11/hello_1.txt";
    }

    public static String imagePath() {
        return "src/test11/EaRfXFPUYAEGtmk.jpg";
    }

    public static void readFile(String path) {
        File file = new File(path);
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            int l;
            while ((l = inputStream.read()) != -1) {
                System.out.print((char) l);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void readImage(String path) {
//        File srcFile = new File(path);
//        File dirFile = new File("src/test11/EEEEE.jpg");
//        InputStream inputStream = null;
//        OutputStream outputStream = null;
//        try {
//            inputStream = new FileInputStream(srcFile);
//            outputStream = new FileOutputStream(dirFile);
//            int l;
//            // 也可以使用byte数组，byte[] b = new byte[1000];
//            while ((l = inputStream.read()) != -1) {
//                outputStream.write(l);
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            if (inputStream != null) {
//                try {
//                    inputStream.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//            if (outputStream != null) {
//                try {
//                    outputStream.close();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//        }
    }
}
